#include<iostream>
#include<string>
using namespace std;

/*模板---类模板
1.写法：template<typename/class T>
		class 类名{};
2.【注意】
  (1)数据类型必须要明显的显示出来；
     e.g ADD<int> a1(2, 6);
  (2)类模板中的函数也是函数模板；
  (3)模板参数有一个或者多个；
  (4)<>里面可以定义模板参数，也可以定义普通参数(常量);
*/

/*template<typename T>
class ADD{
	T a;
	T b;
public:
	ADD(T sa, T sb)
	{
		a = sa;
		b = sb;
	}
	T sum();
};

template<typename T>//在类外定义函数时，要再写一次template<typename T>
T ADD<T>::sum()     //此处应该写为ADD<T>
{
	return a + b;
}

int main()
{
	ADD<int> ad1(5, 8); //此处的 ad 的类型是ADD<int>型
	cout << ad1.sum();
	
	ADD<double> ad2(2.7, 7.2);
	cout << ad2.sum();
	return 0;
}*/

/*template<typename T, int n>
class ADD{
	T a[n];
public:
	ADD(T sa[n])
	{
		int i = 0;
		for(i = 0; i < n; i++)
			a[i] = sa[i];
	}
	T Sum()
	{
		int i = 0;
		T sum = 0;
		for(i = 0; i < n; i++)
			sum += a[i];
		cout << sum << endl;
	}
};

int main()
{
	int a[3] = {3, 5, 8};
	double b[2] = {2.6, 3.5};
	ADD<int, 3> ad1(a);
	ad1.Sum();
	ADD<double, 2> ad2(b);
	ad2.Sum();
	return 0;
}*/

/*class stu
{
	int ID;
	string name;
public:
	stu(int id = 0, string n = " ")
	{
		ID = id;
	    name = n;
	}
	void show()
	{
		cout << ID << "  " << name << endl;
	}
};

class tea
{
	string name;
	double wage;
public:
	tea (string n = " ", double w = 0)
	{
		name = n;
		wage = w;
	}
	void show()
	{
		cout << name << "  " << wage << endl;
	}
};

template<typename T, int size>
class Manage
{
	T m[size];
public:
	Manage(T person[])
	{
		int i = 0;
		for(i = 0; i < size; i++)
			m[i] = person[i];
	}
	void xianshi()
	{
		int i = 0;
		for(i = 0; i < size; i++)
			m[i].show();
	}
};

int main()
{
	stu s[3] = {stu(1001, "zhangsan"), stu(1002, "lisi"), stu(1003, "wangwu")};
	tea t[2] = {tea("zhao", 7100), tea("qian", 7200)};
	
	Manage<stu, 3> m1(s);
	m1.xianshi();
	Manage<tea, 2> m2(t);
	m2.xianshi();
	return 0;
}*/
